package net.uman.service;

import java.util.ArrayList;
import java.util.List;

import net.uman.dao.UserDao;
import net.uman.entity.User;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import net.uman.framework.modules.orm.Page;
import net.uman.framework.modules.orm.PropertyFilter;
import net.uman.util.Constants;

/**
 * 安全相关实体的管理类, 包括用户,角色,资源与授权类.
 * 
 * @author zoule
 */
//Spring Bean的标识.
@Component
//默认将类中的所有函数纳入事务管理.
public class UserManager extends Manager {


	@Autowired
	private UserDao userDao;

	public User getUser(Long id) {
		return userDao.get(id);
	}

	public List<User> getUserList() {
		return userDao.getAll();
	}

	public User getUserByLoginName(String loginName) {
		List<PropertyFilter> filters = new ArrayList<PropertyFilter>();
		filters.add(new PropertyFilter("filter_EQS_loginName",loginName));
		List<User> users = userDao.find(filters);
		if(users.size()<=0||users.size()>1) return null;
		else return users.get(0);
	}

	public Page<User> getUserPage(Page<User> page, List<PropertyFilter> filters) {
		return page = userDao.findPage(page, filters);
	}

	public List<User> getOperatorList() {
		List<PropertyFilter> filters = new ArrayList<PropertyFilter>();
		filters.add(new PropertyFilter("filter_EQI_type",String.valueOf(Constants.USER_TYPE_PLATER)));
		return userDao.find(filters);
	}

	public void delete(Long userId) {
		userDao.delete(userId);
	}

	public void save(User user) {
		userDao.save(user);
	}
	
}
